<template>
    <div id="ResearchChart" :style="{ width: props.width, height: props.height }"></div>
</template>
<script setup lang="ts">
import { onMounted } from 'vue';
import * as echarts from 'echarts';
const props = defineProps<{ width: string, height: string }>();

onMounted(() => {
    try {
        drawChart();
    } catch (error) {
        console.error(error);
    }
})
async function drawChart() {
    // const loginData = await GetLoginData()
    const c = document.getElementById('ResearchChart')
    if (!c) {
        console.error('元素不存在！')
        return;
    }
    const chart = echarts.init(c);
    const option: echarts.EChartsOption = {
        title: {
            text: '近年来论文发表统计'
        },
        tooltip: {
            trigger: 'axis'
        },
        legend: {
            data: ['《SCIENCE》、《NATURE》', 'SCI、SSCI', 'SCIE、EI、ISTP']
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        toolbox: {
            feature: {
                saveAsImage: {}
            }
        },
        xAxis: {
            type: 'category',
            boundaryGap: false,
            data: ["2019","2020","2021","2022","2023"]
            // data: loginData.dates
        },
        yAxis: {
            type: 'value'
        },
        series: [
            {
                name: '《SCIENCE》、《NATURE》',
                type: 'line',
                stack: 'Total',
                data: [23,78,99,109,12]
                // data: loginData.teacherLoginCounts
            },
            {
                name: 'SCI、SSCI',
                type: 'line',
                stack: 'Total',
                data:[10,72,39,8,92]
            },
            {
                name: 'SCIE、EI、ISTP',
                type: 'line',
                stack: 'Total',
                data: [12,51,47,55,21]
            }
        ]
    };
    chart.setOption(option)
}
</script>